package util;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class GmailUtilities {
	private static String smtpHostName="smtp.alu.itba.edu.ar";
	private static String userSend;
	private static String toSend;
	
	public GmailUtilities(String user, String to){
		userSend=user;
		toSend=to;
	}
	
	
	public  void connectSend(String mensaje) throws Exception {
//		boolean debug = true;
		Properties props = new Properties();
		props.put("mail.smtp.host", smtpHostName);

		Session session = Session.getDefaultInstance(props,
				null);
//		session.setDebug(debug);

		Message msg = new MimeMessage(session);

		InternetAddress addressFrom = new InternetAddress(userSend);

		msg.setFrom(addressFrom);
		InternetAddress addressTo = new InternetAddress(toSend);
		msg.setRecipient(Message.RecipientType.TO, addressTo);

		msg.setSubject("ERROR FATAL");
		msg.setContent(mensaje, "text/plain");
		msg.setSentDate(new java.sql.Date(new java.util.Date().getTime()));
		Transport.send(msg);
	}
}
